//
//  EditTableViewController.m
//  ComputerTableViewStoryboard
//
//  Created by student on 16/3/7.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "EditTableViewController.h"

#import "BIDPresident.h"
#import "PresidentDetailTableViewController.h"

@interface EditTableViewController ()<PresidentDetailTableViewControllerDelegate>

@property (nonatomic,strong) NSMutableArray *presidents;

// 用于记录当前用户选中项
@property (nonatomic,strong) NSIndexPath *curSel;
@end

@implementation EditTableViewController

- (NSMutableArray *)presidents
{
    if (_presidents == nil)
    {
        _presidents = [NSMutableArray array];
        NSString *path = [[NSBundle mainBundle] pathForResource:@"Presidents" ofType:@"plist"];
        NSData *data = [NSData dataWithContentsOfFile:path];
        NSKeyedUnarchiver *unArch = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
        NSArray *arr = [unArch decodeObjectForKey:@"Presidents"];
        [_presidents addObjectsFromArray:arr];
    }
    return _presidents;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.presidents.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    BIDPresident *pre = self.presidents[indexPath.row];
    cell.textLabel.text = pre.name;
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@-%@",pre.fromYear,pre.toYear];
    return cell;
    
}

// 将要选中,该方法在prepareForSegue之前运行
// 注意!在此方法里记录你选中的行
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.curSel = indexPath;
    return indexPath;
}

@end
